package com.leetcode.partition8;

/**
 * @author `RKC`
 * @date 2021/9/10 9:25
 */
public class LC704二分查找 {

    public static int search(int[] nums, int target) {
        int left = 0, right = nums.length;
        while (right >= left) {
            int mid = left + ((right - left) >> 1);
            if (nums[mid] > target) right = mid;
            else if (nums[mid] < target) left = mid + 1;
            else return mid;
        }
        return -1;
    }

    public static void main(String[] args) {
        int[] nums = {5};
        int target = 5;
        System.out.println(search(nums, target));
    }
}
